package com.tb.controller;

import com.tb.dubbo.InatureService;
import com.tb.pojo.Nature;
import com.tb.utils.Msg;
import com.tb.utils.ReturnList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @api {get} /nature/list 查询规格参数 刘献强
 * @apiDescription 查询商品规格参数信息
 * @apiGroup Nature API
 *
 * @apiParam {String}  goodsId 商品ID
 *
 * @apiParamExample {json} 请求参数格式:
 *      {
 *          "goodsId":"1",
 *      }
 *
 * @apiVersion 1.0.0
 *
 * @apiSuccessExample {json} 正确返回值:
 *      {
 *     "code": 0,  //状态码 0:成功;1:失败
 *     "msg": "",   //请求结果
 *
 *         "total": 2,    //总条目数
 *         "list": [      //请求的数据
 *             {
 *                 "id": 1,
 *                 "nature": "主体",
 *                 "goodsId": "1",
 *                 "naturev": [
 *                     {
 *                         "id": 1,
 *                         "natureValue": "苹果",
 *                         "natureKey": "品牌",
 *                         "natureId": null,
 *                         "map": null
 *                     }
 *                 ],
 *                 "text": null
 *             },
 *             {
 *                 "id": 2,
 *                 "nature": "基本信息",
 *                 "goodsId": "1",
 *                 "naturev": [
 *                     {
 *                         "id": 2,
 *                         "natureValue": "金色",
 *                         "natureKey": "机身颜色",
 *                         "natureId": null,
 *                         "map": null
 *                     }
 *                 ],
 *                 "text": null
 *             }
 *         ]
 *     }
 * }
 *
 * @apiErrorExample {json} 错误返回值:
 *     {
 *     "code": 1,
 *     "msg": "参数不合法",
 *     "data": null
 * }
 *
 * @apiSampleRequest /nature/list
 */
@RestController
@RequestMapping("/nature")
public class NatureController {
    @Autowired
    private InatureService natureService;
    //查询商品规格参数
    @GetMapping("/list")
    public Msg getNaturesByGoodsId(@RequestParam(name = "goodsId",defaultValue = "") String goodsId){
        if(goodsId!=null&&goodsId.length()>0){
            Map<String,Object> map=new HashMap<>();
            map.put("goodsId",goodsId);
            long count=natureService.getNatures(map).size();
            List<Nature> list = natureService.getNatures(map);
            ReturnList returnList=ReturnList.get(count,list);
            return Msg.success(returnList);
        }else{
            return Msg.error(1,"参数不合法");
        }
    }


}
